home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-11-17 | 7.9 KB | 229 lines | [TEXT/CWIE] |
- // ===========================================================================
- // LCGIApplication.cp ©1995 Brian Todoroff All rights reserved.
- // ===========================================================================
- //
- // Commercial or for-profit use subject to licence. Contact btodorof@hmc.edu.
- //
- // This class may only be distributed with the complete CGI++ Framework
- // package. For further information contact the author at btodorof@hmc.edu.
- //
- // This file contains the code for a PowerPlant application class which
- // supports the CGI inteface provided by WebSTAR and MacHTTP.
- //
- #include "LCGIApplication.h"
-
- // ---------------------------------------------------------------------------
- // • LCGIApplication // replace this with your App type
- // ---------------------------------------------------------------------------
- // Constructor
-
- LCGIApplication::LCGIApplication()
- {
- }
-
-
- // ---------------------------------------------------------------------------
- // • ~LCGIApplication // replace this with your App type
- // ---------------------------------------------------------------------------
- // Destructor
- //
-
- LCGIApplication::~LCGIApplication()
- {
- }
-
- // ---------------------------------------------------------------------------
- // • StartUp
- // ---------------------------------------------------------------------------
- // This function lets you do something when the application starts up.
- // For example, you could issue your own new command, or respond to a system
- // oDoc (open document) event.
-
- void
- LCGIApplication::StartUp()
- {
- }
-
- // ---------------------------------------------------------------------------
- // • ObeyCommand
- // ---------------------------------------------------------------------------
- // Respond to commands
-
- Boolean
- LCGIApplication::ObeyCommand(
- CommandT inCommand,
- void *ioParam)
- {
- return LApplication::ObeyCommand(inCommand, ioParam);
- }
-
- // ---------------------------------------------------------------------------
- // • FindCommandStatus
- // ---------------------------------------------------------------------------
- // This function enables menu commands.
- //
-
- void
- LCGIApplication::FindCommandStatus(
- CommandT inCommand,
- Boolean &outEnabled,
- Boolean &outUsesMark,
- Char16 &outMark,
- Str255 outName)
- {
- LApplication::FindCommandStatus(inCommand, outEnabled, outUsesMark, outMark, outName);
- }
-
- // ===========================================================================
- // • Apple Event Handlers Apple Event Handlers •
- // ===========================================================================
-
- void
- LCGIApplication::HandleAppleEvent(
- const AppleEvent &inAppleEvent,
- AppleEvent &outAEReply,
- AEDesc &outResult,
- long inAENumber)
- {
- StAEDescriptor targD;
- LCHandleStream SData;
- CGIData theData;
- int count;
-
- switch (inAENumber) {
-
- case 7000:
- SData<<"Detected 'WWW' event, type 'srch'"<<endl;
- SData<<"Please update your copy of MacHTTP."<<endl;
- targD.GetOptionalParamDesc(inAppleEvent, '----', typeWildCard);
- break;
-
- case 7002:
- // Detected WWW event, type sdoc, #7002
- targD.GetOptionalParamDesc(inAppleEvent, '----', typeWildCard);
- count=GetHandleSize(targD.mDesc.dataHandle);
- theData.direct=new char[count+1];
- memcpy(theData.direct,*targD.mDesc.dataHandle,count);
- theData.direct[count]=0x00;
-
- targD.GetOptionalParamDesc(inAppleEvent, 'kfor', typeWildCard);
- count=GetHandleSize(targD.mDesc.dataHandle);
- theData.search=new char[count+1];
- memcpy(theData.search,*targD.mDesc.dataHandle,count);
- theData.search[count]=0x00;
-
- targD.GetOptionalParamDesc(inAppleEvent, 'user', typeWildCard);
- count=GetHandleSize(targD.mDesc.dataHandle);
- theData.uname=new char[count+1];
- memcpy(theData.uname,*targD.mDesc.dataHandle,count);
- theData.uname[count]=0x00;
-
- targD.GetOptionalParamDesc(inAppleEvent, 'pass', typeWildCard);
- count=GetHandleSize(targD.mDesc.dataHandle);
- theData.pass=new char[count+1];
- memcpy(theData.pass,*targD.mDesc.dataHandle,count);
- theData.pass[count]=0x00;
-
- targD.GetOptionalParamDesc(inAppleEvent, 'frmu', typeWildCard);
- count=GetHandleSize(targD.mDesc.dataHandle);
- theData.fromuser=new char[count+1];
- memcpy(theData.fromuser,*targD.mDesc.dataHandle,count);
- theData.fromuser[count]=0x00;
-
- targD.GetOptionalParamDesc(inAppleEvent, 'addr', typeWildCard);
- count=GetHandleSize(targD.mDesc.dataHandle);
- theData.caddr=new char[count+1];
- memcpy(theData.caddr,*targD.mDesc.dataHandle,count);
- theData.caddr[count]=0x00;
-
- targD.GetOptionalParamDesc(inAppleEvent, 'post', typeWildCard);
- count=GetHandleSize(targD.mDesc.dataHandle);
- theData.post=new char[count+1];
- memcpy(theData.post,*targD.mDesc.dataHandle,count);
- theData.post[count]=0x00;
-
- targD.GetOptionalParamDesc(inAppleEvent, 'meth', typeWildCard);
- count=GetHandleSize(targD.mDesc.dataHandle);
- theData.method=new char[count+1];
- memcpy(theData.method,*targD.mDesc.dataHandle,count);
- theData.method[count]=0x00;
-
- targD.GetOptionalParamDesc(inAppleEvent, 'svnm', typeWildCard);
- count=GetHandleSize(targD.mDesc.dataHandle);
- theData.sname=new char[count+1];
- memcpy(theData.sname,*targD.mDesc.dataHandle,count);
- theData.sname[count]=0x00;
-
- targD.GetOptionalParamDesc(inAppleEvent, 'svpt', typeWildCard);
- count=GetHandleSize(targD.mDesc.dataHandle);
- theData.sport=new char[count+1];
- memcpy(theData.sport,*targD.mDesc.dataHandle,count);
- theData.sport[count]=0x00;
-
- targD.GetOptionalParamDesc(inAppleEvent, 'scnm', typeWildCard);
- count=GetHandleSize(targD.mDesc.dataHandle);
- theData.cginame=new char[count+1];
- memcpy(theData.cginame,*targD.mDesc.dataHandle,count);
- theData.cginame[count]=0x00;
-
- targD.GetOptionalParamDesc(inAppleEvent, 'ctyp', typeWildCard);
- count=GetHandleSize(targD.mDesc.dataHandle);
- theData.ctype=new char[count+1];
- memcpy(theData.ctype,*targD.mDesc.dataHandle,count);
- theData.ctype[count]=0x00;
-
- targD.GetOptionalParamDesc(inAppleEvent, 'refr', typeWildCard);
- count=GetHandleSize(targD.mDesc.dataHandle);
- theData.referer=new char[count+1];
- memcpy(theData.referer,*targD.mDesc.dataHandle,count);
- theData.referer[count]=0x00;
-
- targD.GetOptionalParamDesc(inAppleEvent, 'Agnt', typeWildCard);
- count=GetHandleSize(targD.mDesc.dataHandle);
- theData.agent=new char[count+1];
- memcpy(theData.agent,*targD.mDesc.dataHandle,count);
- theData.agent[count]=0x00;
-
- outResult.descriptorType='TEXT';
- HandleCGICall(theData,SData);
- outResult.dataHandle = SData.DetachDataHandle();
- break;
-
- default:
- LApplication::HandleAppleEvent(inAppleEvent, outAEReply,
- outResult, inAENumber);
- break;
- }
- }
-
- void LCGIApplication::HandleCGICall(struct CGIData &data,LCHandleStream &sout)
- {
- sout<<"This is comming from HandleCGICall in LCGIApplication"<<endl;
- sout<<"You need to make a sub-class of CCGIApp and"<<endl;
- sout<<"override the HandleCGICall method. See the <CGI Starter App>"<<endl;
- sout<<"code for more information."<<endl<<endl;
- sout<<"The data recived is "<<endl;
- sout<<"direct: "<<data.direct<<endl; //direct parameter
- sout<<"search: "<<data.search<<endl; //search parameters
- sout<<"uname: "<<data.uname<<endl; //current user name
- sout<<"pass: "<<data.pass<<endl; //current user password
- sout<<"fromuser:"<<data.fromuser<<endl; //
- sout<<"caddr: "<<data.caddr<<endl; //client ip address
- sout<<"post: "<<data.post<<endl; //post parameters
- sout<<"method: "<<data.method<<endl; //method (post or get)
- sout<<"sname: "<<data.sname<<endl; //server name
- sout<<"sport: "<<data.sport<<endl; //server port
- sout<<"cginame: "<<data.cginame<<endl; //cgi name as called
- sout<<"ctype: "<<data.ctype<<endl; //content type
- sout<<"referer: "<<data.referer<<endl; //referer
- sout<<"agent: "<<data.agent<<endl; //client agent program
- sout<<endl;
- sout<<"<H3>That's It For Now!</H3>"<<endl;
- sout<<endl<<"Based on the CGI++ Framework for PowerPlant"<<endl;
- sout<<"Contact the author at btodorof@hmc.edu"<<endl;
- sout<<"Bug reports and suggestions appreciated."<<endl;
- return;
- }
-
-
-